package game.entity.item;

import edu.monash.fit2099.engine.Actor;
import edu.monash.fit2099.engine.Exit;
import edu.monash.fit2099.engine.Item;
import edu.monash.fit2099.engine.Location;
import game.CoinPoint;
import game.entity.actor.Allosaurs;
import game.entity.actor.Brachiosaur;
import game.entity.actor.Stegosaur;
import game.util.LocationUtil;

import java.util.List;

public class Egg<T> extends Item {
    T target;
    private int age = 0;
    private int growTurn;

    public Egg() {
        this("egg",'e',true,10);
    }

    public Egg(String name, char displayChar, boolean portable, int growTurn) {
        super(name, displayChar, portable);
        this.growTurn = growTurn;
    }

    @Override
    public void tick(Location currentLocation) {
        age++;
        if(age >= growTurn){
            try {
                Actor actor = (Actor) target.getClass().newInstance();
                //egg的位置可以放actor就放
                if(currentLocation.canActorEnter(actor)){
                    currentLocation.addActor(actor);
                    System.out.println(name +" was grown at "+ LocationUtil.getLocationPrettyString(currentLocation));
                    currentLocation.removeItem(this);

                    if(actor instanceof Stegosaur){
                        CoinPoint.addPoints(100,"Stegosaur grown");
                    }else if(actor instanceof Brachiosaur){
                        CoinPoint.addPoints(1000,"Brachiosaur grown");
                    }else if(actor instanceof Allosaurs){
                        CoinPoint.addPoints(1000,"Allosaurs grown");
                    }
                }else{
                    System.out.println("no location to grow,skip");
                }
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }


    @Override
    public int getsoldPoints() {
        if(target instanceof Stegosaur){
            return 200;
        }
        if(target instanceof Brachiosaur){
            return 500;
        }
        if(target instanceof Allosaurs){
            return 1000;
        }
        return 0;
    }
}
